import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 角色常量
// SYSTEM_USER 超级管理员
// TENANT_USER 平台管理员
// ORG_USER 物流公司
// INDIVIDUAL_USER 车队长

/* Layout */
import Layout from '@/layout'

/* Router Modules */
import accountManage from './modules/accountManage'
// import attachmentManage from './modules/attachmentManage'
import systemManage from './modules/systemManage'
import dispatchManage from './modules/dispatchManage'
import financialManage from './modules/financialManage'
import orderManage from './modules/orderManage'
import reportCensus from './modules/reportCensus'
import reportManage from './modules/reportManage'
import resourceManage from './modules/resourceManage'
import sysNotification from './modules/sysNotification'
import trajectoryPosition from './modules/trajectoryPosition'
import userProfileManage from './modules/userInfoManage'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  }
]

export const asyncRoutes = [
  // testManager,
  userProfileManage,
  orderManage,
  financialManage,
  resourceManage,
  // attachmentManage,
  accountManage,
  dispatchManage,
  reportCensus,
  reportManage,
  trajectoryPosition,
  systemManage,
  sysNotification,
  {
    path: '/personalCenter',
    component: Layout,
    redirect: '/personalCenter/personalCenter',
    children: [
      {
        path: 'personalCenter',
        component: () => import('@/views/personalCenter/index'),
        name: 'personalCenter',
        meta: { title: '个人中心', icon: 'dashboard', roles: ['SYSTEM_USER', 'TENANT_USER', 'ORG_USER', 'INDIVIDUAL_USER'] }
      }
    ]
  },
  {
    path: '/FiltrateColumn',
    component: Layout,
    redirect: '/FiltrateColumn/FiltrateColumn',
    children: [
      {
        path: 'filtrateText',
        component: () => import('@/components/FiltrateColumn'),
        name: 'filtrateColumn',
        meta: { title: '筛选栏封装测试', icon: 'dashboard', roles: ['SYSTEM_USER', 'TENANT_USER', 'ORG_USER', 'INDIVIDUAL_USER'] }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
